package com.mike.mybatisplus.controller;


import com.mike.mybatisplus.pojo.Student;
import com.mike.mybatisplus.service.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ Author     ：mmzs.
 * @ Date       ：Created in  2021/11/27 12:47
 * @ Description：数据库 ( student )  控制层
 */
@RestController
public class StudentController {

    @Autowired
    private StudentServiceImpl studentService;

    @GetMapping("queryOne")
    public Student queryById (Long id) {
        return studentService.queryOne(id);
    }

    @GetMapping("queryAll")
    public List<Object> queryAll () {
        return studentService.queryAll();
    }


    @GetMapping("insertOne")
    public boolean insertOne (Student student) {
        return studentService.additionOne(student);
    }

    @GetMapping("updateOne")
    public boolean updateOne (Student student) {
        return studentService.alterOne(student);
    }

    @GetMapping("deleteOne")
    public boolean deleteOne (Long id) {
        return studentService.removeOne(id);
    }

    // 部署高并发
    @GetMapping("queryAlled")
    public void transmissionInformation () {
        Student student = new Student();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                queryAll();
            }
        };
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        for (int i = 0; i < 30; i++) {
            executorService.submit(runnable);
        }
    }
}
